-
Notifications
You must be signed in to change notification settings - Fork 832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(sdk-logs): ensure default resource attributes are used as fallbacks when a resource is passed to LoggerProvider #4564
fix(sdk-logs): ensure default resource attributes are used as fallbacks when a resource is passed to LoggerProvider #4564
Conversation
…ks when a resource is passed to LoggerProvider Before this Resource.default() attributes would only be used if *no* resource was given to LoggerProvider. That would mean that 'service.name' and others could be missing, e.g. when called from NodeSDK.
small reproSave this to "foo.js": const { SeverityNumber } = require('@opentelemetry/api-logs');
const { LoggerProvider, SimpleLogRecordProcessor } = require('@opentelemetry/sdk-logs');
const { ExportResultCode } = require('@opentelemetry/core');
const { Resource } = require('@opentelemetry/resources');
class InspectLogRecordExporter {
export(logs, resultCallback) {
console.dir(logs, { depth: 5 });
resultCallback({ code: ExportResultCode.SUCCESS });
}
shutdown() {
return Promise.resolve();
}
}
const loggerProvider = new LoggerProvider({
resource: new Resource({ foo: 'bar' }),
});
loggerProvider.addLogRecordProcessor(
new SimpleLogRecordProcessor(new InspectLogRecordExporter())
);
const logger = loggerProvider.getLogger('default');
logger.emit({
severityNumber: SeverityNumber.INFO,
severityText: 'INFO',
body: 'this is a log record body',
attributes: { anAttr: 'aValue' },
}); And run it without this fix:
That shows that the created LogRecord is missing the attributes from
|
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4564 +/- ##
==========================================
+ Coverage 92.83% 92.84% +0.01%
==========================================
Files 328 328
Lines 9486 9487 +1
Branches 2035 2035
==========================================
+ Hits 8806 8808 +2
+ Misses 680 679 -1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, thanks 👍
…ks when a resource is passed to LoggerProvider (open-telemetry#4564) Before this Resource.default() attributes would only be used if *no* resource was given to LoggerProvider. That would mean that 'service.name' and others could be missing, e.g. when called from NodeSDK. Co-authored-by: Marc Pichler <[email protected]>
Before this, Resource.default() attributes would only be used if no
resource was given to LoggerProvider. That would mean that
'service.name' and others could be missing, e.g. when called from
NodeSDK.
Here is where, for example, NodeSDK passes in a resource to LoggerProvider:
opentelemetry-js/experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Lines 360 to 362 in aabd1a9